<template> 
  <div>
    <ContentWrap>
      <el-form :model="form" :inline="true" class="demo-form-inline mb-4">
        <el-form-item label="海报名称">
          <el-input v-model="form.posterName" placeholder="请输入海报名称" class="!w-200px" />
        </el-form-item>
        <el-form-item label="海报类型">
          <el-select v-model="form.posterTypeId" placeholder="请选择海报类型" class="!w-200px" clearable>
            <el-option v-for="item in posterTypeList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <!-- 推荐人 -->
        <el-form-item label="推荐人">
            <el-input v-model="form.referrerNickname" placeholder="会员ID或昵称" class="!w-200px" />
        </el-form-item>
        <!-- 被推荐人 -->
        <el-form-item label="被推荐人">
          <el-input v-model="form.userNickname" placeholder="会员ID或昵称" class="!w-200px" />
        </el-form-item>
        <el-form-item >
          <el-button type="primary" @click="handleSearch">搜索</el-button>
        </el-form-item>
      </el-form>
    </ContentWrap>
    <ContentWrap>
      <el-table :data="tableData" :loading="loading"  stripe :show-overflow-tooltip="true" >
        <el-table-column label="扫码时间" prop="bindTime" align="center" >
          <template #default="scope">
            {{ formatDate(scope.row.createTime) }}
          </template>
        </el-table-column>
        <el-table-column label="海报名称" prop="posterName" align="center" />
        <el-table-column label="海报类型" prop="typeName" align="center" />
        <el-table-column label="推荐人信息/会员ID/昵称" prop="referrerNickname" align="center" />
        <el-table-column label="被推荐人信息/会员ID/昵称" prop="userNickname" align="center" />
      </el-table>
      <Pagination :total="total" v-model:page="form.pageNo" v-model:limit="form.pageSize" @pagination="getList" />
    </ContentWrap>
  </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue'
import { getPosterReferralRelationPage,getPosterTypeList } from '@/api/allApplication/poster/index';
import { formatDate } from '@/utils/formatTime'
const form = ref({
  posterName: '',
  posterTypeId: undefined as any,
  referrerNickname: '',
  userNickname: '',
  pageNo:1,
  pageSize:10
})
const state = reactive({
  tableData: [],
  total: 0,
 
  posterTypeList: [] as any[]
})
const { tableData,total,posterTypeList } = toRefs(state)
const loading = ref(false)
const handleSearch = () => {
  form.value.pageNo = 1
  getList()
}
const getList = async () => {
  const res = await getPosterReferralRelationPage({
    posterName: form.value.posterName,
    posterTypeId: form.value.posterTypeId,
    referrerNickname: form.value.referrerNickname,
    refereeInfo: form.value.userNickname,
    pageNo: form.value.pageNo,
    pageSize: form.value.pageSize,
  })
  state.tableData = res.list || []
  state.total = res.total || 0
}
const getTypelist = async () => {
  const list = await getPosterTypeList()
  state.posterTypeList = list || []
}
onMounted( async () => {
  await getTypelist()
  await getList()
})
</script>
